#include "types.h"
#include "FastAlloc.h"
#include <malloc.h>
#include <vector>
#include <iterator>

CFastAlloc	*CFastAlloc::s_pAllocator = NULL;

CFastAlloc::CFastAlloc( u32 numReservedBytes/*, u32 numTables = 0*/ )
{
	assert( s_pAllocator==NULL );
	s_pAllocator = this;

	m_numReservedBytes = numReservedBytes;
	m_pData = malloc( m_nDataSize );

	//m_numTables = numTables?numTables:numReservedBytes/4;
	//m_pTable = new SAllocTable[m_numTables];

	//m_currTableItem = 0;
	//m_bFreedTableItem = false;

std::vector<int> someList;
int total = 0;
std::for_each(someList.begin(), someList.end(), [&total](int x) {
  total += x;
});
std::cout << total;

}

CFastAlloc::~CFastAlloc(void)
{
	free( m_pData );
	//delete[] m_pTable;
}


void *CFastAlloc::Alloc( u32 numBytes )
{
	assert( s_pAllocator->m_pData );
	u32 nNew = s_pAllocator->m_nDataSize+numBytes;
	if( nNew <= s_pAllocator->m_numReservedBytes )
	{
		void *pRet = IncPointer(s_pAllocator->m_pData, s_pAllocator->m_nDataSize);
		s_pAllocator->m_nDataSize = nNew;
		return pRet;
	}
	else
	{
		assert( "Memory Allocation Failed"&&0 );
		return NULL;
	}
}